#ifndef _RESOURCE_H
#define _RESOURCE_H

#include <QMouseEvent>
#include <QPoint>
#include <QTimer>
#include <QJsonObject>
#include <QJsonArray>
#include <QJsonParseError>
#include <QStack>
#include "log.h"
#include "pthread.h"
#include "resourceitem.h"
#include "adddiritem.h"
#include "httpcommon.h"
#include "ui_resource.h"
#include "globaldata.h"

extern class Home;

class Resource : public QWidget {
	Q_OBJECT
public:
	Resource(Home *home);
	~Resource();
	void resetWidget();
	static void* processRefreshResourceListProc(void* args);
	void refreshResourceList();
protected:
	bool eventFilter(QObject* obj, QEvent* e);
	public Q_SLOTS:
	void on_pbRefresh_clicked();
	void on_pbRoot_clicked();
	void on_pbChild_clicked();
	void on_cbCheckAll_clicked();
	private Q_SLOTS:
	void deleteSlot(QString id, QString name);
	void refreshResourceListSlot();
	void enterDirSlot(QString dir, QString dirName);
	void checkSlot(QString id, bool checked);
	void confirmOKSlot();
	void deleteAddDirSlot(QString);
	void addDirSlot(QString, QString);

Q_SIGNALS:
	void uploadSignal(QString);
	void showMessageSignal(QString, int);
	void refreshResourceListSignal();

private:
	void initWidget();
	void loadResourceData();
	void analyseResourceData(QString id, QJsonArray children);
	void genResourceWidget(QString parentId);
	void loadRoute();
	void updateHistoryButtonStyle(bool hoverPre=false, bool hoverNext=false);
	void deleteCheckResource();
	QString getItemID();
private:
	Ui::Resource ui;
	Home *m_home;
	pthread_t m_tidRefreshResourceListProcess;
	QMap<QString, ResourceItem*> m_resourceMap;
	QMap<QString, QJsonArray> m_childrenMap;
	QString m_currentDirID;
	QString m_currentDirName;
	QStack<QString> m_preDir;
	QStack<QString> m_nextDir;
	QMap<QString, bool> m_checkedMap;
	QMap<QString, AddDirItem*> m_addDirMap;
};

#endif//_RESOURCE_H
